﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZX.Web.UI.Controls;
using System.Text;

namespace ZX.WebApp.EHR
{
    public partial class hrViewEmployeeInfo : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string employeeId = this.GetStringFromQueryString("id", string.Empty);
            //获取基本信息
            ZX.EHR.Library.hrEmployee hrEmployeeInstance = ZX.Common.Globals.getEntity("hrEmployee") as ZX.EHR.Library.hrEmployee;
            ZX.BLL.Extend.BaseBussnies hrEmployeeBll = new ZX.BLL.Extend.BaseBussnies(hrEmployeeInstance);
            string hrEmployeeCondition = string.Format("ID='{0}'", employeeId);
            ZX.EHR.Library.hrEmployee hrEmployeeEntry = hrEmployeeBll.GetEntityByCondition(hrEmployeeCondition) as ZX.EHR.Library.hrEmployee;
            this.CName.Value = hrEmployeeEntry.CName;
            this.EName.Value = hrEmployeeEntry.EName;
            this.Gender.Value = hrEmployeeEntry.Gender == "M" ? "男" : "女";
            this.IDCardNO.Value = hrEmployeeEntry.IDCardNO;
            this.BirthDate.Value = hrEmployeeEntry.BirthDate.ToString("yyyy-MM-dd");
            this.EmployeeCode.Value = hrEmployeeEntry.EmployeeCode;
            this.JoinDate.Value = hrEmployeeEntry.JoinDate.ToString("yyyy-MM-dd");
            this.PhoneNo.Value = hrEmployeeEntry.PhoneNo;
            this.Email.Value = hrEmployeeEntry.Email;
            //获取员工试用期限
            ZX.SYS.Library.DatPhraseDetail Instance2 = ZX.Common.Globals.getEntity("DatPhraseDetail") as ZX.SYS.Library.DatPhraseDetail;
            ZX.BLL.Extend.BaseBussnies bll = new ZX.BLL.Extend.BaseBussnies(Instance2);
            string condition = string.Format("PhraseID='{0}'", hrEmployeeEntry.ProbationPeriod.ToString());
            ZX.SYS.Library.DatPhraseDetail employeeTypeEntity = bll.GetEntityByCondition(condition) as ZX.SYS.Library.DatPhraseDetail;
            if (employeeTypeEntity != null) this.ProbationPeriod.Value = employeeTypeEntity.PhraseText;
            //获取职位等级
            condition = string.Format("PhraseID='{0}'", hrEmployeeEntry.PositionLevel.ToString());
            employeeTypeEntity = bll.GetEntityByCondition(condition) as ZX.SYS.Library.DatPhraseDetail;
            if (employeeTypeEntity != null) this.PositionLevel.Value = employeeTypeEntity.PhraseText;
            //获取最高学历
            condition = string.Format("ClassID=(select ClassID from DatPhraseClass where ClassValue='EducationDegree') and PhraseValue='{0}'", hrEmployeeEntry.TopDegree);
            employeeTypeEntity = bll.GetEntityByCondition(condition) as ZX.SYS.Library.DatPhraseDetail;
            if (employeeTypeEntity != null) this.TopDegree.Value = employeeTypeEntity.PhraseText;
            //获取部门
            ZX.EHR.Library.DatDepartment deptInstance = ZX.Common.Globals.getEntity("DatDepartment") as ZX.EHR.Library.DatDepartment;
            ZX.BLL.Extend.BaseBussnies deptBll = new ZX.BLL.Extend.BaseBussnies(deptInstance);
            string deptCondition = string.Format("DeptID='{0}'", hrEmployeeEntry.DepartmentID.ToString());
            ZX.EHR.Library.DatDepartment deptEntiey = deptBll.GetEntityByCondition(deptCondition) as ZX.EHR.Library.DatDepartment;
            this.DepartmentID.Value = deptEntiey.DeptName;
            //获取岗位
            ZX.EHR.Library.DatPost postInstance = ZX.Common.Globals.getEntity("DatPost") as ZX.EHR.Library.DatPost;
            ZX.BLL.Extend.BaseBussnies postBll = new ZX.BLL.Extend.BaseBussnies(postInstance);
            string postCondition = string.Format("PostID='{0}'", hrEmployeeEntry.PostID.ToString());
            ZX.EHR.Library.DatPost postEntiey = postBll.GetEntityByCondition(postCondition) as ZX.EHR.Library.DatPost;
            this.PostID.Value = postEntiey.PostName;
            //
            this.Nationality.Value = hrEmployeeEntry.Nationality;
            this.BloodType.Value = hrEmployeeEntry.BloodType;
            this.MaritalStatus.Value = hrEmployeeEntry.MaritalStatus == "0" ? "未婚" : "已婚";
            this.Hometown.Value = hrEmployeeEntry.Hometown;
            this.PersonnelArchivesArea.Value = hrEmployeeEntry.PersonnelArchivesArea;
            this.HouseholdRegistration.Value = hrEmployeeEntry.HouseholdRegistration;
            if (hrEmployeeEntry.JoinJobDate.ToString("yyyy-MM-dd") != "0001-01-01" && hrEmployeeEntry.JoinJobDate.ToString("yyyy-MM-dd") != "1900-01-01")
            {
                this.JoinJobDate.Value = hrEmployeeEntry.JoinJobDate.ToString("yyyy-MM-dd");
            }
            this.SocialInsuranceNO.Value = hrEmployeeEntry.SocialInsuranceNO;
            this.HouseCardNO.Value = hrEmployeeEntry.HouseCardNO;
            this.BankCardNO.Value = hrEmployeeEntry.BankCardNO;
            this.UrgencyContactMan.Value = hrEmployeeEntry.UrgencyContacRelation;
            this.UrgencyContactPhoneNO.Value = hrEmployeeEntry.UrgencyContactPhoneNO;
            this.SpecialDesc.Value = hrEmployeeEntry.SpecialDesc;
            this.Habits.Value = hrEmployeeEntry.Habits;
            this.Residence.Value = hrEmployeeEntry.Residence;
            DateTime birDate = DateTime.Parse(this.BirthDate.Value);
            DateTime now = DateTime.Now;
            var age = now.Year - birDate.Year;
            var m = now.Month - birDate.Month;
            if (m < 0)
                age--;
            this.age.Value = age.ToString();
            //获取工作经历

            //获取教育信息

            //获取培训信息

            //获取技能信息
        }
    }
}